var attendanceType;
var timedTaskId;
var groupid;
var iconid;
var subid;
var menuid;
var index;
var taskDetailsListTijaio;
var taskDetailsList;
var timedTaskVal;
var weekTimesText = '';
var pubTime = '';
var enabled='1';
//var taskTypeShow
$(function () {
	groupid = ly.getUrlParam("groupid");
	iconid = ly.getUrlParam("iconid");
	subid = ly.getUrlParam("subid");
	menuid = ly.getUrlParam("menuid");
	attendanceType = ly.getUrlParam("attendanceType");
	timedTaskId = ly.getUrlParam("timedTaskId");

	console.log("ly="+ly);
	console.log("groupid="+groupid);
	console.log("iconid="+iconid);
	console.log("menuid="+menuid);
	console.log("attendanceType="+attendanceType);
	console.log("timedTaskId="+timedTaskId);

	if (attendanceType == 2) {

		$("#Map1").hide();
		$(".taskEndTime").addClass("hide");
		$(".taskEndTime2").show();
		$(".timedTaskRadioBOX").hide();
		$(".timedTaskRadioBOX2").show();

		$(".body_title").text("查询");
		$(".form").getForm({
			'ajaxform': true,
			timedTaskId: timedTaskId
		}, function (data) {
			console.log(data)

			// if (data.taskType == 3) {
			// 	$(".taskLine").removeClass('hide')
			// }
			if (data.enabled && data.enabled == 1) {
				$('#timedTask2 input[name="timedTask"]').eq(0).prop("checked", false);
				$('#timedTask2 input[name="timedTask"]').eq(1).prop("checked", true);
			} else {
				$('#timedTask2 input[name="timedTask"]').eq(0).prop("checked", true);
				$('#timedTask2 input[name="timedTask"]').eq(1).prop("checked", false);
			}
			if(data.taskCategories==2){//临时任务
				$(".taskEndTime").addClass("hide");
				$(".taskEndTime2").hide();
				$(".timedTaskRadioBOX").hide();
				$(".timedTaskRadioBOX2").hide();
				$("#publishMode").removeClass("hide");
				if(data.publishType==2){
					$(".publishTime").removeClass("hide");
					$('.publishTime').find("input#publishTime").addClass('required');
				}
			}
			if (data.regularWeekViewList) {
				var weekHtml = '';
				for (let i = 0; i < data.regularWeekViewList.length; i++) {
					if (data.regularWeekViewList[i].selectionState == 1) {
						weekHtml += '<li class="weekTimes_active">' + data.regularWeekViewList[i].weekDay + '</li>'
					}
				}
				$("#weekHtml").html(weekHtml);
			}

			changeIsSpecify(data.isSpecify, data.businessId);
			//$("#save-btn-commodityClassification").hide();

			if (data.taskType == 3) {
				$(".taskLine").removeClass('hide')
				$("#Map1BOX").removeClass('hide');
				if (data.taskDetailsList != null && data.taskDetailsList != '') {
					taskDetailsList = data.taskDetailsList;
					writeTaskDetailsList(data.taskDetailsList);
					//mapsShow()
				}
			} else {
				$(".taskLine").addClass('hide')
				$("#Map1BOX").addClass('hide');
			}


			//selectUsersList(data.userId,"","","1");
			$("#taskType").getSelect({
				type: "radio",
				asName: "taskType",
				code: "taskType",
				default: data.taskType
			});
			$("#taskLevel").getSelect({
				type: "radio",
				asName: "taskLevel",
				code: "taskLevel",
				default: data.taskLevel
			});
			$("#taskCategories").getSelect({
				type: "radio",
				asName: "taskCategories",
				code: "taskCategories",
				default: data.taskCategories
			});
			$("#publishType").getSelect({
				type: "radio",
				asName: "publishType",
				code: "publishType",
				default: data.publishType
			});

			$("#isSpecify").getSelect({
				type: "radio",
				asName: "isSpecify",
				list: [{
						value: "1",
						display: "指定人员"
					},
					{
						value: "2",
						display: "指定部门"
					},
					{
						value: "3",
						display: "指定工种"
					}
				],
				default: data.isSpecify
			});

			//------------------------------------------------------


		});
		$(".addDetailsList").remove();
		$("#save-btn-commodityClassification").hide();
		$("#timedTask2 input[name='timedTask']").attr("disabled", "disabled");
		$(".radio,#publishTime").attr("disabled", "disabled");
	} else {
		$('#timedTask input[name="timedTask"]').eq(1).prop("checked", true);
		$(".taskEndTime").removeClass("hide");
		$(".taskEndTime2").hide();
		$(".timedTaskRadioBOX").show();
		$(".timedTaskRadioBOX2").hide();
		$(".taskLine").hide();
		$("#Map1BOX").hide();
		changeIsSpecify("3");
		$("#taskType").getSelect({
			type: "radio",
			asName: "taskType",
			code: "taskType",
			default: '2'
		});
		$("#publishType").getSelect({
			type: "radio",
			asName: "publishType",
			code: "publishType",
			default: '1'
		});

		$("#taskLevel").getSelect({
			type: "radio",
			asName: "taskLevel",
			code: "taskLevel",
			default: '1'
		});
		$("#taskCategories").getSelect({
			type: "radio",
			asName: "taskCategories",
			code: "taskCategories",
			default: '1'
		});
		$("#isSpecify").getSelect({
			type: "radio",
			asName: "isSpecify",
			list: [{
					value: "1",
					display: "指定人员"
				},
				{
					value: "2",
					display: "指定部门"
				},
				{
					value: "3",
					display: "指定工种"
				}
			],
			default: '3'
		});
		$('#addr').singleMapSelector({
			address: '',
			lng: '',
			lat: ''
		}, function (d) {
			orgAdd = d.address;
			latitude = d.lat;
			longitude = d.lng;
			$("#location").val(orgAdd);
			$("#log").val(longitude);
			$("#lat").val(latitude);
			// $("#equipmentAddress").val(orgAdd);
			$("#writeAddress").removeClass("hide");
		});
	}

	$("#timedTask").on("input", "input[name='timedTask']", function () {
		timedTaskVal = $("input[name=timedTask]:checked").val();

		if (timedTaskVal == 2) {
			//$('.timedTaskBox').show()
			enabled = "1";
		} else {
			//$('.timedTaskBox').hide()
			enabled = "0";
		}

		console.log("timedTask="+enabled);
	})
	$("#timedTask2").on("input", "input[name='timedTask']", function () {
		timedTaskVal = $("input[name=timedTask]:checked").val();

		if (timedTaskVal == 2) {
			$('.timedTaskBox').show()
		} else {
			$('.timedTaskBox').hide()
		}

	})


	$('.weekTimes').on('click', 'ul li', function () {
		if ($(this).attr('class') == 'weekTimes_active') {
			$(this).removeClass('weekTimes_active')
		} else {
			$(this).addClass('weekTimes_active')
		}

	})


	$("#taskType").on("input", "input[name='taskType']", function () {
		if ($(this).val() == '3') {
			$(".addDetailsList").removeClass("hide");
			$("#Map1").hide();
			$("#Map1BOX").hide();
			$('#writeAddress').hide();
			request({
				url: site.gateUrl + '/back/taskLine/selectTaskLineBackList',
				data: {
					size: 1000,
					num: 1
				},
				ajaxform: true,
				type: 'post',
				callback: function (r) {
					if (r.code == "rest.success") {
						var list = r.result.list,
							html = '<option value="">请选择</option>';
						for (var i = 0; i < list.length; i++) {
							html += '<option value="' + list[i].id + '">' + list[i].lineName + '</option>'
						}
						$("#lineId").html(html);
					} else {
						ly.toast(r.msg);
					}
				}
			});
		} else {
			$("#Map1").show();
			$(".addDetailsList").addClass("hide");
			//$("#addDetailsList").show();
		}
	});

	//提交
	$("body").on("click", "#save-btn-commodityClassification", function (event) {
		event.preventDefault();
		var success = $('.form').validate('submitValidate');
		var weekTimesTexts = '';
		//验证通过提交表单
		if (attendanceType == 2) {
			modifierFom();
		} else {
		
				$('.weekTimes ul li').each(function (i, v) {
					if (v.className == 'weekTimes_active') {
						weekTimesTexts += v.innerText + ','
					}
				})
			var checkEndTime = $("#checkEndTime").val();
			console.log("checkEndTime="+checkEndTime);
			pubTime = checkEndTime.split(':')[0]+':'+checkEndTime.split(':')[1]
			console.log("pubTime="+pubTime);
			weekTimesText = weekTimesTexts.slice(0, weekTimesTexts.length - 1);
			
			var taskCategories = $("input[name=taskCategories]:checked").val();
			console.log("taskCategories="+taskCategories);
			if(taskCategories==1&&weekTimesTexts==''){
				ly.toast("日期选择不能为空");
				return;
			}else if(taskCategories==2){
				pubTime = $("#publishTime").val();
				console.log("pubTime="+pubTime);
			}
			submitFom();
		}
	})

	$("body").on("change", "#isSpecify", function () {
		var isSpecify = $("#isSpecify input:checked").val();
		changeIsSpecify(isSpecify);
	});
	//确认任务线路
	$("body").on("click", "#submit-btn-audit", function () {
		taskDetailsListTijaio = new Array();
		var obj = {};
		$(".id").each(function () {
			var id = $(this).val();
			obj = {
				'equipmentId': id,
				'taskOperation': $("#taskOperation" + id).find("option:selected").val(),
				'taskFlow': $(".taskFlow" + id).html(),
				'detailsExplain': $("#detailsExplain" + id).val()
			}
			taskDetailsListTijaio.push(obj);
			obj = {};
		});
		console.log(taskDetailsListTijaio);
		layer.close(index);
	});



	$("body").on("change", "#taskCategories", function () {
		var taskCategories = $("input[name=taskCategories]:checked").val();
		console.log("taskCategories="+taskCategories);
		if (taskCategories == 1) {
			//20200428,改bug清空临时选择
			$('input[type=radio][name="publishType"]:checked').attr("checked", false);
			$(".taskEndTime").removeClass("hide");
			$('.timedTaskRadio').show();
			$('.timedTaskBox').show();
			$("#publishMode").addClass("hide");
			$(".publishTime").addClass("hide");
			$(".publishTime").find("div.col-7").removeClass('error success');
			$(".publishTime").find("div.col-3.valid").remove();
			$('.publishTime').find("input#publishTime").removeClass('required');
		} else {
			$('.timedTaskRadio').hide();
			$('.timedTaskBox').hide();
			$("#publishMode").removeClass("hide");
			$(".taskEndTime").addClass("hide");

			var publishType = $("input[name=publishType]:checked").val();
			console.log("publishType="+publishType);
			if(publishType ==2){
				$(".publishTime").removeClass("hide");
				$('.publishTime').find("input#publishTime").addClass('required');
			}else{
				$(".publishTime").addClass("hide");
				$(".publishTime").find("div.col-7").removeClass('error success');
				$(".publishTime").find("div.col-3.valid").remove();
				$('.publishTime').find("input#publishTime").removeClass('required');
			}
		}
	});

	$("body").on("change","#publishType",function(){
		var publishType = $("input[name=publishType]:checked").val();
		console.log("publishType="+publishType);
		if(publishType ==2){
			$(".publishTime").removeClass("hide");
			$('.publishTime').find("input#publishTime").addClass('required');
		}else{
			$(".publishTime").addClass("hide");
			$(".publishTime").find("div.col-7").removeClass('error success');
			$(".publishTime").find("div.col-3.valid").remove();
			$('.publishTime').find("input#publishTime").removeClass('required');
		}
	});
	var points = [];


	function writeTaskDetailsList(taskDetailsList) {
		var maps = new AMap.Map('allmap');
		var markers;
		var detailsList = "";

		$.each(taskDetailsList, function (i, o) {
			detailsList += "<tr><td>" + o.taskFlow + "</td>" +
				"<td>" + o.taskLat + "</td><td>" + o.taskLog + "</td><td>" + o.taskOperationDisplay + "</td>" +
				"<td>" + o.detailsExplain + "</td></tr>";
			points.push({
				lng: o.taskLog,
				lat: o.taskLat,
				data: 1,
			})
		});
		$("#detailsList").append(detailsList);

		///console.log(points)



		for (var i = 0; i < points.length; i++) {

			var jfong = [points[i].lng, points[i].lat];
			markers = new AMap.Marker({
				resizeEnable: true, //是否监控地图容器尺寸变化
				zoom: 6, //初始地图级别
				position: jfong,
				zIndex: 101,
				map: maps,

			});

			var markerContent = document.createElement("div");
			markerContent.className = "markerBOX";
			var markerImg = document.createElement("img");
			markerImg.className = "markerlnglat";
			markerImg.src = "../../img/mark_bs.png"

			markerContent.appendChild(markerImg);


			var markerNum = document.createElement("span");
			markerNum.className = 'marker-number';
			markerNum.innerHTML = i + 1;
			markerContent.appendChild(markerNum);

			markers.setContent(markerContent); //更新点标记内容
		}



		maps.setZoom(10, 8)
		maps.add(markers); //添加到地图

	}



});

function changeIsSpecify(isSpecify, businessId) {

	if (isSpecify == '1') {
		//指定人员
		$(".changeWork").hide();
		$(".changeTeam").hide();
		$(".changeUserId").show();
		selectUsersList(businessId);
	} else if (isSpecify == '2') {
		//指定部门
		$(".changeWork").hide();
		$(".changeUserId").hide();
		$(".changeTeam").show();
		selectTeamList(businessId);
	} else {
		//指定工种
		$(".changeTeam").hide();
		$(".changeUserId").hide();
		$(".changeWork").show();
		selectWorkerList(businessId);
	}
}

function mapsShow() {

}
/*
 * 提交表单
 */
function submitFom() {


	var taskName = $("#taskName").val();
	var taskStatement = $("#taskStatement").val();
	var taskType = $("#taskType input:checked").val();
	var taskLevel = $("#taskLevel input:checked").val();
	var taskCategories = $("#taskCategories input:checked").val();
	var isSpecify = $("#isSpecify input:checked").val();
	var publishType = $("#publishType input:checked").val();
	var location = $("#location").val();
	var lat = $("#lat").val();
	var log = $("#log").val();
	var lineId = $("#lineId").val();
	var businessId = "";
	var taskEndTime = "";


	if (taskCategories == 1 && taskType == 3) {
		taskEndTime = $("#taskEndTime").val();
	}

	if (isSpecify == "1") {
		//指定人
		$("input[name=userId]:checked").each(function () {
			if ($(this).val() != null) {
				businessId += $(this).val() + ",";
			}
		});
        if (businessId == null || businessId == ''||businessId == undefined) {
            ly.toast("指定人员为空");
            return false;
        }
	} else if (isSpecify == "2") {
		//指定部门
		$("input[name=teamId]:checked").each(function () {
			if ($(this).val() != null) {
				businessId += $(this).val() + ",";
			}
		});
        if (businessId == null || businessId == ''||businessId == undefined) {
            ly.toast("指定部门为空");
            return false;
        }
	} else {
		//指定工种
		$("input[name=workerId]:checked").each(function () {
			if ($(this).val() != null) {
				businessId += $(this).val() + ",";
			}
		});

        if (businessId == null || businessId == ''||businessId == undefined) {
            ly.toast("指定工种为空");
            return false;
        }
	}

	if (taskType == 2) {
		if (log == null || lat == '') {
			ly.toast("请选择地址");
			return false;
		}
	}

	/*var isUsing = $("#isUsing input:checked").val();*/
	var task = {
		'taskName': taskName,
		'taskStatement': taskStatement,
		'taskType': taskType,
		'taskLevel': taskLevel,
		'taskCategories': taskCategories,
		'isSpecify': isSpecify,
		'taskLat': lat,
		'taskLog': log,
		'taskEndTime': taskEndTime,
		'publishType':publishType
	};
	var task2 = {
		'taskName': taskName,
		'taskStatement': taskStatement,
		'taskType': taskType,
		'taskLevel': taskLevel,
		'taskCategories': taskCategories,
		'isSpecify': isSpecify,
		'taskEndTime': taskEndTime,
		'publishType':publishType
	};
	var obj = {};
	var url = site.apiUrl + "/moble/task/insertTimedTask"; //apiUrl
	//20200414:修改bug
	publishType = $("input[name=publishType]:checked").val();

	console.log("publishType="+publishType);
	if(publishType!=null || publishType=="undefined") {
		if (publishType == 2) {
			var publishTime = $("#publishTime").val();
			if (publishTime == null || publishTime == "") {
				ly.toast("请选择发布日期");
				return false;
			}
		}
		if (pubTime == ":undefined") {
			ly.toast("请选择发布时间");
			return false;
		}
	}
	if(taskName == ""){
		ly.toast("请输入任务名称");
		return false;
	}
	if (attendanceType == 1) {
		//新增
		obj = {
			'task': task,
			'location':location,
			'businessId': businessId,
			'taskDetailsList': taskDetailsListTijaio,
			'enabled':enabled,
			'pubTime': pubTime,
			'pubWeeks': weekTimesText, // 选择星期几,
		};
	} else {
		//修改
		var thisId = $("#id").val();
		obj = {
			'task': task2,
			'businessId': businessId,
			'taskDetailsList': taskDetailsListTijaio,
			'id': thisId
		};
	}
	if (taskType == "3") {
		if ($.trim(lineId) == "") {
			ly.toast("请选择任务路线");
			return false;
		} else {
			obj.task.lineId = lineId;
		}
	}
	if(publishType==2){
		obj.task.publishTime= $("#publishTime").val().substring(0,16);
	}
	console.log(646);
	console.log(task, businessId, businessId!='',taskDetailsListTijaio,enabled,pubTime,weekTimesText);

	console.log("---------------------------------------------------------------------------------");
	console.log("task!=:"+task!='');
	console.log("businessId:"+businessId!='');
	console.log("taskDetailsListTijaio:"+taskDetailsListTijaio!='');
	console.log("enabled:"+enabled!='');
	console.log("pubTime:"+pubTime !='');

	console.log("task="+task);
	console.log("businessId="+businessId);
	console.log("taskDetailsListTijaio="+taskDetailsListTijaio);
	console.log("enabled="+enabled);
	console.log("pubTime="+pubTime);

	console.log("---------------------------------------------------------------------------------");

	if(task!='' && businessId!='' && taskDetailsListTijaio!='' && enabled!='' && pubTime !=''){
		console.log(111111111);
	}else{
		console.log(222222222);
	}

	if(task!='' && businessId!='' && taskDetailsListTijaio!='' && enabled!=''){
		request({
			url: url,
			data: obj,
			type: "post",
			callback: function (f) {
				console.log(f);
				if (f.code == "rest.success") {
					if (attendanceType == 1) {
						ly.alert('保存成功', function () {
							ly.goto("new-task-list.html");
						});
					} else {
						ly.alert('修改成功', function () {
							ly.goto("new-task-list.html");
						});
					}
				} else {
					ly.toast(f.desc);
				}
			}
		});
		console.log(692);
	}else{
		console.log("url="+url);
		console.log(695);
		ly.toast("输入完整信息");	
	}


}

function modifierFom() {
	var taskName = $("#taskName").val();
	if (taskCategories == 1 && taskType == 3) {
		taskEndTime = $("#taskEndTime").val();
	}
	var timedTaskVals = timedTaskVal == 2 ? '1' : '0'
	/*var isUsing = $("#isUsing input:checked").val();*/
	var obj = {};
	var url = site.apiUrl + "/back/task/updateTimedTaskByIdAndEnable"; //apiUrl
	obj = {
		'timedTaskId': timedTaskId,
		'enabled': timedTaskVals,
	};
	request({
		url: url,
		data: obj,
		type: "get",
		'ajaxform': true,
		callback: function (f) {
			console.log(f);
			if (f.code == "rest.success") {
				ly.alert('保存成功', function () {
					ly.goto("new-task-list.html");
				});

			} else {
				ly.toast(f.desc);
			}
		}
	});
}


//打开弹窗
function creatDetailsList(taskDetailsList) {
	$("#equipmentType").getSelect({
		type: "select",
		asName: "equipmentType",
		code: "equipmentType",
		default: ''
	});
	selectEquipmentListBack('', '', taskDetailsList);
	index = layer.open({
		title: false,
		type: 1,
		area: ['65%', '600px'], //设置宽度,高度自适应
		closeBtn: 0,
		content: $(".create_merchant"),
		success: function (layero, index) {
			$("#layui-layer" + index).find(".goback,.icon-close").on("click", function () {
				document.getElementById("formMerchant").reset();
				$("#layui-layer" + index).find(".valid").remove();
				$("#layui-layer" + index).find("div").removeClass('error success');
				layer.close(index);
			});
		}
	});
}


//选择上级部门
function selectTeamList(businessId) {
	var list = new Array();
	request({
		url: site.gateUrl + "/back/team/selectTeamList",
		data: {
			'num': 1,
			'size': 100,
			'isUsing': 1
		},
		type: "get",
		ajaxform: true,
		callback: function (f) {
			console.log(f);
			if (f.code == "rest.success") {
				/*var obj = {value:' ',display:'请选择'};
				list.push(obj);*/
				var obj = {};
				if (f.result.list != null && f.result.list != '') {
					obj = {};
					$.each(f.result.list, function (i, o) {
						obj = {
							value: o.id,
							display: o.teamName
						};
						list.push(obj);
					});
				}
				$("#teamId").getSelect({
					type: "checkbox",
					asName: "teamId",
					list: list,
					default: businessId
				});
			}
		}
	});
}

//选择设备
function selectEquipmentListBack(equipmentType, equipmentName, taskDetailsList) {

	var changeThisList = "";
	var listEquipmentId = "";
	$("#changeThisList").empty();
	if (taskDetailsList != null && taskDetailsList != '') {
		$.each(taskDetailsList, function (i, o) {
			changeThisList = "<tr class='deleteThisEquipment" + o.id + "'><input class='id' type='hidden' value='" + o.id + "'><td>" + (i + 1) + "</td><td>" + o.equipmentName + "</td><td onclick=\"deleteThisEquipment('" + o.id + "')\">删除</td></tr>";
			listEquipmentId += o.id + ",";
		});
		$("#changeThisList").append(changeThisList);
	}
	request({
		url: site.gateUrl + "/back/attendanceBack/selectEquipmentListBack",
		data: {
			'num': 1,
			'size': 100,
			'isUsing': 1,
			'equipmentType': equipmentType,
			'equipmentName': equipmentName
		},
		type: "get",
		"ajaxform": true,
		callback: function (f) {
			console.log(f);
			if (f.code == "rest.success") {
				var equipmentList = null;
				if (f.result.list != null && f.result.list != '') {
					$("#equipmentList").empty();
					obj = {};
					$.each(f.result.list, function (i, o) {
						var c = "";
						if (listEquipmentId != null && listEquipmentId != '') {
							if (o.id.indexOf(listEquipmentId) == -1) {
								c = "已选择";
							} else {
								c = "选择";
							}
						} else {
							c = "选择";
						}
						equipmentList += "<tr><td>" + o.equipmentName + "</td>" +
							"<td>" + o.equipmentTypeDisplay + "</td>" +
							"<td>" + o.lat + "</td><td>" + o.log + "</td><td>" + o.equipmentAddress + "</td>" +
							"<td class='equipment" + o.id + "' onclick=\"changeThisEquipment('" + o.id + "','" + o.equipmentName + "')\">" + c + "</td>";
					});
				}
				$("#equipmentList").append(equipmentList);
			}
		}
	});
}

/****
 * 
 * @param {Object} id
 * @param {Object} equipmentName
 */
function changeThisEquipment(id, equipmentName) {

	if ($(".equipment" + id).html() == '已选择') {
		ly.toast("已选择，不可重复选择");
		return false;
	}
	var length = parseFloat($("#changeThisList tr").length) + 1;
	var changeThisList = "<tr class='deleteThisEquipment" + id + "'><input class='id' type='hidden' value='" + id + "'><td class='taskFlow" + id + " paixu'>" + length + "</td><td>" + equipmentName + "</td>" +
		"<td><select id='taskOperation" + id + "' class=''></select></div></td><td><input type='text' class='ipt' id='detailsExplain" + id + "'></td><td onclick=\"deleteThisEquipment('" + id + "')\">删除</td></tr>";
	$("#changeThisList").append(changeThisList);
	$(".equipment" + id).html("已选择");
	selectDictBasicsWithGroup(id);

}

function deleteThisEquipment(id) {
	$(".deleteThisEquipment" + id).remove();
	$(".equipment" + id).html("选择");
	$(".paixu").each(function (i, o) {
		$(o).html(i + 1);
	});
}
//选择工种
function selectWorkerList(businessId) {
	var list = new Array();
	request({
		url: site.gateUrl + "/back/worker/selectWorkerList",
		data: {
			'num': 1,
			'size': 100,
			'isUsing': 1
		},
		type: "get",
		ajaxform: true,
		callback: function (f) {
			console.log(f);
			if (f.code == "rest.success") {
				var obj = {};
				if (f.result.list != null && f.result.list != '') {
					obj = {};
					$.each(f.result.list, function (i, o) {
						obj = {
							value: o.id,
							display: o.workerName
						};
						list.push(obj);
					});
				}
				$("#workerId").getSelect({
					type: "checkbox",
					asName: "workerId",
					list: list,
					default: businessId
				});
			}
		}
	});
}

//选择用户
function selectUsersList(businessId) {
	var list = new Array();

	var teamId = "";
	var userType = "";
	var assumeOffice = "";
	var backstage_access_personnelstyle = window.localStorage.getItem("backstage-access-personnelstyle");
	if (backstage_access_personnelstyle == 1) {
		assumeOffice = "";
	} else {
		assumeOffice = "2";
		if(window.localStorage.getItem("backstage-access-teamId") == 'undefined'){
			teamId = '';
		}else{
			teamId = window.localStorage.getItem("backstage-access-teamId");
		}
		userType = window.localStorage.getItem("backstage_access_personnelstyle");
	}
	request({
		url: site.gateUrl + "/sUsers/selectUsersList",
		data: {
			'num': 1,
			'size': 1000,
			'isUsing': 1,
			'userType': userType,
			'teamId': teamId
			// 'assumeOffice': assumeOffice
		},
		type: "get",
		"ajaxform": true,
		callback: function (f) {
			console.log(f);
			if (f.code == "rest.success") {
				var obj = {};
				if (f.result.list != null && f.result.list != '') {
					obj = {};
					$.each(f.result.list, function (i, o) {
						obj = {
							value: o.id,
							display: o.nickName
						};
						list.push(obj);
					});
				}
				$("#userId").getSelect({
					type: "checkbox",
					asName: "userId",
					list: list,
					default: businessId
				});
			}
		}
	});

}

//选择字典
function selectDictBasicsWithGroup(id) {
	var list = new Array();
	request({
		url: site.gateUrl + "/dictBasic/selectDictBasicsWithGroup",
		data: {
			'code': 'taskOperation'
		},
		type: "get",
		"ajaxform": true,
		callback: function (f) {
			console.log(f);
			if (f.code == "rest.success") {
				var options = '';
				if (f.result != null && f.result != '') {
					$.each(f.result, function (i, o) {
						options += "<option value='" + o.value + "'>" + o.display + "</option>"
					});
					$("#taskOperation" + id).append(options);
				}
			}
		}
	});
}

/***
 * 选择搜索
 */
function changeSelectTeamList() {

	var equipmentType = $('select[name=equipmentType] option:checked').val();
	var equipmentName = $("#equipmentName").val();
	selectEquipmentListBack(equipmentType, equipmentName, taskDetailsList);
}